<?php

/**
 * Created by PhpStorm.
 * User: li
 * Date: 15-10-18
 * Time: 下午11:47
 */
class Email extends MY_Pc_Api_Controller
{
    function __construct(){
        parent::__construct();
    }

    /**
     * 发送邮件
     *
     * @return json
     */
    function do_send(){
        $email = trim($this->input->post('email'));
        $func = trim($this->input->post('func'));
        if(!$email or !$func)
            $this->json_response(false);
        if($func=='rebind')
            $this->auth();
        $subject = $this->config->item($func.'_email_word','auth'); //register_email_word
        if($this->auth_nuan->has_key_exists($func.'_email')){
            $data = $this->auth_nuan->get_key($email,$func.'_email');
        }
        if(empty($data)){
            $this->json_response(false);
        }
        $this->send_email('welcome',$email,$subject,$data);
        $this->json_response(true);
    }

    /**
     * 验证
     *
     * @return void
     */
    function verify(){
        $key  = $this->input->post('verify_key');
        $func = $this->input->get('func');
        $subject = $this->input->get('subject');
        $account = $this->input->get('account');
        $email = $account.'@'.$subject;
        if(!$key or !$func)
            $this->_show_message('验证码错误',403,'/welcome');
        if(!$this->auth_nuan->email_active($email,$key,true))
            $this->_show_message($this->auth_nuan->get_error());
        $this->show_message('激活成功',200,'/user/account');
    }
}